package com.ld.security.server.admin.modules.ge.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.common.mybatis.base.entity.ESortEntity;
import com.ld.security.common.mybatis.base.entity.SuperEntity;
import com.ld.security.common.mybatis.base.vo.ProxyVo;
import com.ld.security.common.mybatis.constant.SqlCondition;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@TableName("ge_link")
@ApiModel("关联表")
@Data
public class GeLinkEntity  extends SuperEntity implements ESortEntity,ProxyVo
{
  @ApiModelProperty("表x")
  @SqlKey(SqlCondition.eq)
    private String tableNameX;

  @ApiModelProperty("表y")
  @SqlKey(SqlCondition.eq)
  private String tableNameY;


  @ApiModelProperty("字段x")
  @SqlKey(SqlCondition.eq)
    private String fieldNameX;



  @ApiModelProperty("字段y")
  @SqlKey(SqlCondition.eq)
    private String fieldNameY;

  @SqlKey(SqlCondition.eq)
  @ApiModelProperty("模型编号")
  private String modelId;



  @SqlKey(SqlCondition.eq)
  @ApiModelProperty("数据源编号")
  private String dataSourceId;


  @SqlKey
  @ApiModelProperty("顺序值")
  private Integer sortVal;


  @ApiModelProperty("标题x")
  private String labelX;

  @ApiModelProperty("标题y")
  private String labelY;


  public boolean eqLink(GeLinkEntity e){
    return this.fieldNameX.equals(e.getFieldNameX()) && this.fieldNameY.equals(e.getTableNameY());


  }

  @Override
  public void saveBefore() {
    String sp="\\.";
  //  if(fieldNameX != null){
      this.tableNameX =  this.fieldNameX.split(sp)[0];
    //}
    //if(tableNameY != null){
      this.tableNameY =  this.fieldNameY.split(sp)[0];
    //}



  }
}
